<!DOCTYPE html>
<html lang="en">

  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>报关</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <!--<link href="css/nprogress.css" rel="stylesheet">-->

    <!-- Custom Theme Style -->
    <link href="css/custom.min.css" rel="stylesheet">
  </head>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div id="head">
        </div>

        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">

                  <div class="x_content">

                    <form class="form-horizontal form-label-left" novalidate>

                      <p>发货前的一些<code>手续办理与信息填写</code>需要发送给海关部门验证，请务必填写无误！
                      </p>
                      <span class="section" style="">上传报关表信息</span>


                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="declareImg">上传报关图片<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="declareImg"   type="file">
                        </div>
                        <label style="color: red;" id="imgError"></label>
                      </div>
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          <a href="javascript:;" class="btn btn-primary" onclick="window.history.back(-1)">返回</a>
                          <a id="send" href="javascript:;" class="btn btn-success">提交</a>
                        </div>
                      </div>
                    </form>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->

        <!-- footer content -->
        <footer>

          <div class="clearfix"></div>
        </footer>
        <!-- /footer content -->
      </div>
    </div>

    <!-- jQuery -->
    <script src="js/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="js/fastclick.js"></script>
    <!-- NProgress -->
    <!--<script src="js/nprogress.js"></script>-->
    <!-- validator -->
    <script src="js/validator.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="js/custom.min.js"></script>

    <!-- validator -->
    <script>
      // initialize the validator function
      validator.message.date = 'not a real date';

      // validate a field on "blur" event, a 'select' on 'change' event & a '.reuired' classed multifield on 'keyup':
      $('form')
        .on('blur', 'input[required], input.optional, select.required', validator.checkField)
        .on('change', 'select.required', validator.checkField)
        .on('keypress', 'input[required][pattern]', validator.keypress);

      $('.multi.required').on('keyup blur', 'input', function() {
        validator.checkField.apply($(this).siblings().last()[0]);
      });

      $('form').submit(function(e) {
        e.preventDefault();
        var submit = true;

        // evaluate the form using generic validaing
        if (!validator.checkAll($(this))) {
          submit = false;
        }

        if (submit)
          this.submit();

        return false;
      });
    </script>
    <!-- /validator -->

    <!-- jQuery Smart Wizard -->
    <script>
      $(document).ready(function() {
        $("#head").load("head.html");
        $('.buttonNext').addClass('btn btn-success');
        $('.buttonPrevious').addClass('btn btn-primary');
        $('.buttonFinish').addClass('btn btn-default');
      });
      var $token=window.sessionStorage.getItem('token');
      var $url=window.location.href;
      var $ordid=$url.split("=")[1];
      function _img() {
          if($("#declareImg").val()==null||$("#declareImg").val().length==0){
              $("#imgError").html("图片不能为空");
              return false;
          }else{
              $("#imgError").html("");
              return true;
          }
      }
      $("#declareImg").bind("change",_img);
      $(document).on("click","#send",function () {
          var $declareImg=$("#declareImg")[0].files[0];
          var formDate=new FormData();
          formDate.append("declareImg",$declareImg);
          formDate.append("ordid",$ordid);
          formDate.append("token",$token);
          if(_img()==false){
              return false;
          }else{
          $.ajax({
              type:"post",
              cache:false,
              processData:false,
              contentType:false,
              xhrFields:{withCredentials:true},
              url:"http://localhost:8081/declare/Adddeclare",
              dataType:"json",
              data:formDate,
              success:function (data) {
                  if(data.message=="toShip"){
                      alert("上传报关图片成功")
                      window.location.href="booking_order.html";
                  }else if(data.message=="toAir"){
                      alert("上传报关图片成功")
                      window.location.href="air_order.html";
                  }else if(data.message=="size"){
                      alert("上传图片不能大于500k")
                  }else if(data.message=="fail"){
                      alert("上传图片失败")
                  }else if(data.message=="type"){
                      alert("上传图片格式只能为jpg\jpeg\png\pneg")
                  }else if(data.message=="kong") {
                      alert("上传图片为空")
                  }else{
                      alert("上传图片失败")
                  }
              },
              error:function(){
                  alert("上传报关图片错误");
              }
          })
          }
      })
    </script>
    <!-- /jQuery Smart Wizard -->
  </body>
</html>
